using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db.SupplyChain.Material;


namespace HengTong.ViewModel.SupplyChain.SysRawMaterialVms
{
    public partial class SysRawMaterialListVm : BaseListVm<SysRawMaterialView, SysRawMaterialSearcher>
    {

        protected override IEnumerable<IGridColumn<SysRawMaterialView>> InitGridHeader()
        {
            return new List<GridColumn<SysRawMaterialView>>{
                this.MakeGridHeader(x => x.Name),
                this.MakeGridHeader(x => x.Code),
                this.MakeGridHeader(x => x.GroupCode),
                this.MakeGridHeader(x => x.UnitCode),
                this.MakeGridHeader(x => x.Model),
                this.MakeGridHeader(x => x.Description),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysRawMaterialView> GetSearchQuery()
        {
            var query = DC.Set<SysRawMaterial>()
                .CheckContain(Searcher.Name, x=>x.Name)
                .CheckContain(Searcher.Code, x=>x.Code)
                .CheckContain(Searcher.GroupCode, x=>x.GroupCode)
                .CheckContain(Searcher.UnitCode, x=>x.UnitCode)
                .CheckContain(Searcher.Model, x=>x.Model)
                .Select(x => new SysRawMaterialView
                {
				    ID = x.ID,
                    Name = x.Name,
                    Code = x.Code,
                    GroupCode = x.GroupCode,
                    UnitCode = x.UnitCode,
                    Model = x.Model,
                    Description = x.Description,
                })
                .OrderBy(x => x.Code);
            return query;
        }
    }

    public class SysRawMaterialView : SysRawMaterial{

    }
}
